/*
 * To change this template, choose Tools | Templates
 * and open the template in the editor.
 */
package technotheist.imgcog.util;

/**
 *
 * @author Mitch
 */
public class ColUtil {
    private ColUtil() { }
    
    public static float getRed(int rgb) {
        return ((rgb >> 16) & 0x000000FF)/255f;
    }
    
    public static float getGreen(int rgb) {
        return ((rgb >> 8) & 0x000000FF)/255f;
    }
    
    public static float getBlue(int rgb) {
        return ((rgb) & 0x000000FF)/255f;
    }
    
    public static float getLightness(int rgb) {
        return getLightness(getRed(rgb), getGreen(rgb), getBlue(rgb));
    }
    
    public static float getLightness(float r, float g, float b) {
        return (max(r,g,b) + min(r,g,b)) * 0.5f;
    }
    
    public static float getIntensity(int rgb) {
        return getIntensity(getRed(rgb), getGreen(rgb), getBlue(rgb));
    }
    
    static float THIRD =  1f/3f;
    public static float getIntensity(float r, float g, float b) {
        return (r + g + b) * THIRD;
    }
    
    
    public static float getLuminence_a(int rgb) {
        return getLuminence_a(getRed(rgb), getGreen(rgb), getBlue(rgb));
    }
    
    public static float getLuminence_b(int rgb) {
        return getLuminence_b(getRed(rgb), getGreen(rgb), getBlue(rgb));
    }
    
    public static float getLuminence_a(float r, float g, float b) {
        return 0.299f * r + 0.587f * g + 0.114f * b;
    }
    
    public static float getLuminence_b(float r, float g, float b) {
        return 0.241f * r * r + 0.691f * g * g + 0.068f * b * b;
    }
    
    public static float min(float r, float g, float b) {
        return Math.min(r, Math.min(g, b));
    }
    
    public static float max(float r, float g, float b) {
        return Math.max(r, Math.max(g, b));
    }
}
